package com.example.photography.adapter.product;

import android.content.Context;
import android.net.Uri;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.photography.R;
import com.example.photography.adapter.MyBaseAdapter;
import com.example.photography.bean.ArticlesBean;
import com.example.photography.bean.ProductBean;
import com.facebook.drawee.view.SimpleDraweeView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public abstract class ArticleAdapter extends MyBaseAdapter {
    public ArticleAdapter(List list, Context context) {
        super(list, context);
    }

    @Override
    public View myGetView(int position, View convertView) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.item_article, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        //根据位置得到数据
        ArticlesBean.DataBean.ArticleBean articleBean = (ArticlesBean.DataBean.ArticleBean) list.get(position);
        viewHolder.svCover.setImageURI(Uri.parse(articleBean.getProduct()));
        viewHolder.tvTitle.setText(""+articleBean.getTitle());
        viewHolder.tvCommentNum.setText(""+articleBean.getComment_num());
        viewHolder.tvCollectNum.setText(""+articleBean.getCollect_num());
        viewHolder.tvLikeNum.setText(""+articleBean.getLike_num());
        viewHolder.itemArticle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                setItemListen(articleBean.getId());
            }
        });
        return convertView;
    }


    static
    class ViewHolder {
        @BindView(R.id.sv_cover)
        SimpleDraweeView svCover;
        @BindView(R.id.tv_title)
        TextView tvTitle;
        @BindView(R.id.tv_comment_num)
        TextView tvCommentNum;
        @BindView(R.id.tv_collect_num)
        TextView tvCollectNum;
        @BindView(R.id.tv_like_num)
        TextView tvLikeNum;
        @BindView(R.id.item_article)
        LinearLayout itemArticle;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
    public abstract void setItemListen(int id);
}
